package mylist
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * @author db0@qq.com
	 */
	public class FileItem
	{
		/**
		 *
		 */
		//public var index:int = 0;
		public var file:FileReference;
		public var bmp:Bitmap;
		public var jpeg:ByteArray;
		/**
		 * Number(new Date) / 1000;
		 */
		public var time:uint;//
		/**
		 * 
		 * 0:无 1:正加入列表中  2:列表 3:上传中 4:已上传  5:长按超时加大
		 */
		public var state:String = "null";
		public static const ADDSTAGE:String = "1";
		/**
		 * 2:列表
		 */
		public static const ADDED:String = "2";
		/**
		 * 3:上传中
		 */
		public static const UPLOADING:String = "3";
		/**
		 * 4:已上传
		 */
		public static const UPLOADED:String = "4";
		//public static const DRAG:String = "5";
		
		
		public static var list:Vector.<FileItem> = new Vector.<FileItem>;
		/**
		 * 显示的图块
		 */
		public var uploadItem:IconItem;
		public var size:uint;
		
		public function FileItem(file:FileReference)
		{
			this.file = file;
		}
		
		public static function pushBmp(bmp:Bitmap):void
		{
			var fileItem:FileItem = new FileItem(null);
			fileItem.state =  ADDED;
			fileItem.bmp = bmp;
			list.push(fileItem);
		}
		
		public static function push(files:FileReference):void
		{
			var i:int = 0;
			var isIn:Boolean = false;
			if (files.size > 2 * 1024 *1024) isIn = true;
			while (i < list.length)
			{
				if (sameItem(files, list[i].file))
				{
					isIn = true;
					//logs.adds(isIn);
					break;
				}
				++i;
			}
			
			if (!isIn)
			{
				var fileItem:FileItem = new FileItem(files);
				list.push(fileItem);
			}
		}
		
		public static function sameItem(file1:FileReference, file2:FileReference):Boolean
		{
			if (Boolean(file1 && file2) == false) return false;
			var b:Boolean = (file1.name == file2.name) && (file1.size == file2.size);
			return b;
		}
	
	}

}